package cn.com.open.itembank.service;

import cn.com.open.itembank.dto.ItemBank;
import cn.com.open.itembank.dto.ReturnModel;
import cn.com.open.itembank.entity.CourseItemBank;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;

/**
 * Created by lucky on 2017/9/4.
 */
@FeignClient(name = "item-base-service")
public interface ItemBankRemoteService {

    /**
     * 判断给定appkey是否包含在配置文件的applist许可列表内，如果包含则说明拥有删除题库权的权利.
     *
     * @param appKey appKey
     * @return true ，拥有；false，不拥有
     */
    @GetMapping(value = "/itemBank/hasSuperPermission")
    boolean hasSuperPermission(@RequestParam("appId") String appKey);

    /**
     * 根据题库id获取可用题库信息.
     *
     * @param itemBankId 题库id
     * @return 可用题库信息 course item bank info
     */
    @GetMapping(value = "/itemBank/{id}")
    CourseItemBank getCourseItemBankInfo(@PathVariable(value = "id") String itemBankId);

    /**
     * 新增课程题库.
     *
     * @param model    课程题库信息
     * @param isNative 来源：True，内部；False，外部
     * @return the int
     */
    @PostMapping(value = "/itemBank")
    ReturnModel insert(@RequestBody ItemBank model, @RequestParam("isNative") boolean isNative);

    /**
     * 修改课程题库.
     *
     * @param id         题库id
     * @param name       题库课程名称
     * @return the int
     */
    @PutMapping(value = "/itemBank/{id}")
    int update(@PathVariable(value = "id") String id, @RequestParam("name") String name);

    /**
     * 更新题库状态.
     *
     * @param id 题库ID
     * @return the int
     */
    @PutMapping(value = "/itemBank/{id}/status")
    int changeStatus(@PathVariable(value = "id") String id);

    /**
     * 删除课程题库(外部不允许通过此接口删除).
     *
     * @param itemBankId 题库id
     * @param appKey     appKey
     * @return the int
     */
    @DeleteMapping(value = "/itemBank/{id}")
    int delete(@PathVariable(value = "id") String itemBankId, @RequestParam("appkey") String appKey);

    /**
     * 判断给定的appkey是否拥有给定的题库id的管理权限，如果是题库所有者或者拥有超级权限均视为拥有权限.
     *
     * @param itemBankId 题库id
     * @param appKey     appkey
     * @return true ，拥有；false，不拥有
     */
    @GetMapping(value = "/itemBank/{id}/permission")
    boolean hasPermission(@PathVariable(value = "id") String itemBankId, @RequestParam("appId") String appKey);

}
